package com.swt.controller.T_controller;

import com.alibaba.fastjson.JSON;
import com.swt.domain.Club;
import com.swt.domain.Course;
import com.swt.service.T_service.CoursePKService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
class TCourseController {
    @Resource(name = "CoursePKService")
    private CoursePKService coursePKService;
    //排课添加
    @RequestMapping("/CourseAddPK")
    @ResponseBody
    public String courseAdd(Course course,HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        boolean coursePKServiceAdd = coursePKService.CoursePKServiceAdd(course,clubClubId);
        System.out.println(coursePKServiceAdd);
        return JSON.toJSONString(coursePKServiceAdd);
    }
    //排课查询
    @RequestMapping("/coursePKQuery")
    @ResponseBody
    public String coursePKQuery(int courseClubid,HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        List<Course>  courseList= coursePKService.CoursePKServiceQuery(courseClubid,clubClubId);
        return JSON.toJSONString(courseList);
    }

    //排课排除占用时间查询
    @RequestMapping("/coursePKQueryTime")
    @ResponseBody
    public String coursePKQueryTime(String courseDate,String courseTime,HttpServletRequest httpServletRequest){
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();
        List<Course>  courseList= coursePKService.coursePKQueryTimeService(courseDate,courseTime,clubClubId);
        return JSON.toJSONString(courseList);
    }


    //修改排课查询
    @RequestMapping("/coursePKUpdateQuery")
    @ResponseBody
    public String coursePKUpdateQuery(Course course,HttpServletRequest httpServletRequest){
        System.out.println(course);
        Club club = (Club) httpServletRequest.getSession().getAttribute("CLUB_SESSION_KEY");
        int clubClubId = club.getClubId();

        List<Course>  courseList= coursePKService.coursePKServiceUPdateQuery(course,clubClubId);
        return JSON.toJSONString(courseList);
    }

    //修改排课
    @RequestMapping("/coursePKUpdate")
    @ResponseBody
    public String coursePKUpdate(Course course){
       boolean  courseboolean = coursePKService.coursePKServiceUPdate(course);

        return JSON.toJSONString(courseboolean);
    }

    //删除排课
    @RequestMapping("/coursePKDelete")
    @ResponseBody
    public String coursePKDelete(int id){
        boolean  courseboolean1 = coursePKService.coursePKServiceDelete(id);

        return JSON.toJSONString(courseboolean1);
    }



    public CoursePKService getCoursePKService() {
        return coursePKService;
    }

    public void setCoursePKService(CoursePKService coursePKService) {
        this.coursePKService = coursePKService;
    }
}
